
import 'package:xsdk_flutter/xsdk/framework/bean/x_bean_device.dart';
import 'package:json_annotation/json_annotation.dart';


//定义生成的文件
part 'x_bean_queue_message.g.dart';

@JsonSerializable(explicitToJson: true) //当内部存在嵌套类时使用,不存在也可以使用
class XBaseQueueMessage {

  String? tag;

  //初始化自动尝试(重打)次数
  int defaultTryCount =5;//默认尝试次数(用于恢复)
  int limitTryCount=5;//剩余尝试次数(用于计数)

  //是否优先处理
  bool isPriorityHandle=false;

  //是否心跳包命令
  bool isHeartbeatCommand=false;
  //服务端收到客户端消息回调确认命令(自定义socket通讯)
  bool isMsgReceivedCommand=false;
  //是否打开钱箱命令
  bool isOpenCashDrawerCommand=false;

  /*
    消息ID
     */
  String msgId;

  /*
   是否需要保存到src队列备份,
   记录打印失败时,消息队列恢复重新打印,或打印成功则清除对应的消息队列内容,或请求快麦打印命令匹配消息的如设备地址场景等其他设置
   */
  bool isSaveToQueueSrcMsgList=false;
  /*
  是否自动重试
  失败重打(5次),防漏打机制(本地持久化,队列空余时间自动重打)
   */
  bool isAutoRetry=false;


  //原始消息(string改为dynamic,支持map类型适配socket)
  //String? message_raw;
  dynamic message; //

  dynamic message_other; //
  //List<int>相当于Uint8List  Uint8List.fromList(list<int>)
  List<int>? message_Uint8List;



  //消息写入的(蓝牙,server/client socket)设备名称/地址
  String? deviceName;
  String? bluetoothAddress;//设备地址
  String? characteristicId;//ble指定characteristicId

  String? deviceUUID; //设备id(sn),如:远程设备等

  /*
  属于设备场景类型(一条信息对应一种设备场景,如有多个,在业务接收时判断分开多条信息)
  如设置则优先以此为准,否则以deviceAddress为准打印
   */
  XBaseDeviceScene? deviceScene;
  /*
  属于设备序号(一条信息对应一个设备序号,如有多个,在业务接收时判断分开多条信息)
  '1','2',...
   */
  dynamic deviceSerialNumber;

  //server client socket 使用 //////////////////////////////

  //方向: 是否服务端发送到客户端的消息 否则为客户端发送到服务端,
  bool isServerSendToClientMessage=false;
  String? ip;//
  int port=-1;//

  //是否远程socket消息(结果回调通知远程socket)
  bool isRemoteSocketMessage=false;
  String? remoteIP;//
  int remotePort=-1;//

  /////////////////////////////////////////////////////////

  String? errorLog;//错误日志

  String? createTime;//创建时间
  String? modifyTime;//最新修改时间(重打印时间)
  String? completeTime;//(成功)完成打印时间


  //业务/////////////////////////////////////////////

  //记录其他类型的id,用于保存对应该消息的id返回通知,适用msgId需要为空时使用

  //消息对应的订单信息
  String? orderNo;//订单号
  String? orderId;//订单ID
  String? orderType;//订单类型

  //快麦打印sdk使用
  String? templateId; //模板id
  String? templateType; //模板类型

  List<dynamic>? otherParams; //保存其他参数

  XBaseQueueMessage({
    required this.msgId,
    this.isSaveToQueueSrcMsgList=false,
    this.tag,
    this.message,
    this.message_other,
    this.message_Uint8List,
    this.deviceName,
    this.deviceUUID,
    this.bluetoothAddress,
    this.characteristicId,
    this.deviceScene,
    this.deviceSerialNumber,
    this.isRemoteSocketMessage=false,
    this.remoteIP,
    this.remotePort=-1,
    this.isServerSendToClientMessage=false,
    this.ip,
    this.port=-1,
    this.errorLog,
    this.createTime,
    this.modifyTime,
    this.completeTime,
    this.orderNo,
    this.orderId,
    this.orderType,
    this.templateId,
    this.templateType,
    this.otherParams, //不能使用默认值const [],其不能添加item
    this.defaultTryCount =5,
    this.limitTryCount =5,
    this.isPriorityHandle=false,
    this.isHeartbeatCommand=false,
    this.isMsgReceivedCommand=false,
    this.isOpenCashDrawerCommand=false,
    this.isAutoRetry=false,
  });


  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is XBaseQueueMessage &&
          runtimeType == other.runtimeType &&
          msgId == other.msgId &&
          message == other.message;

  @override
  int get hashCode => msgId.hashCode ^ message.hashCode;

  //添加固定格式: _$自定义的类名FromJson  _$自定义的类名ToJson
  factory XBaseQueueMessage.fromJson(Map<String, dynamic> json) => _$XBaseQueueMessageFromJson(json);
  Map<String, dynamic> toJson() => _$XBaseQueueMessageToJson(this);


}
